package com.shujia.mr.dianxin1;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class DianXinReducer extends Reducer<Text, LongWritable, Text, LongWritable> {
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        //<"47BE1E866CFC071DB19D5E1C056BE28AE24C16E7-8340104",[11,23,1,2,3,0,..]>
        long counts = 0;
        long sum = 0;
        for (LongWritable value : values) {
            sum += value.get();
            counts++;
        }

        //求平均时长
        long avg_time = sum / counts;

        context.write(key, new LongWritable(avg_time));

    }
}
